import { blendColor } from "./blendColor";
export const Uint32Array_ID = idof<Uint32Array>();
/** 混合多个历史颜色,输入已经经过位置去重 */
export function blendColors(input: Uint32Array): Uint32Array[] {
    let col = [] as Uint32Array[];

    //  x, y, color, alpha, color, alpha, blend;
    for (let index = i16(input.length / 7 - 1); index >= 0; index--) {
        const base = index * 7;
        const color1 = input[base + 2];
        const alpha1 = input[base + 3];
        const color2 = input[base + 4];
        const alpha2 = input[base + 5];
        const blend = input[base + 6];

        if (alpha1 === 0 && alpha2 === 0) continue;
        //! 当 alpha2 为 0 的时候，代表橡皮擦
        if (alpha1 === 0 || blend === 0) {
            const temp = input.slice(base, base + 6);
            col.push(temp);
            // 替换行为，不进行混色
            continue;
        }
        const blended = blendColor(color1, alpha1, color2, alpha2);
        const color3 = blended[0];
        const alpha3 = blended[1];
        if (color1 === color3 && alpha3 === alpha1) continue; // 混色前后不变，不更改
        const temp = input.slice(base, base + 6);
        temp[4] = color3;
        temp[5] = alpha3;
        col.push(temp);
    }
    return col;
}
